#include "test_cpuinfo.h"
#include "cm_uart.h"
#include "cm_demo_uart.h"



void cm_test_cpuinfo_operation(unsigned char*cmd[],int len)
{
    if(0 == strcmp("RECORD_START",cmd[2]))
    {
        uint32_t mode = atoi(cmd[3]);
        int32_t cpuinfo_record_start = cm_cpuinfo_record_start(mode);
        cm_demo_printf("cm_cpuinfo_record_start ret:%d\n",cpuinfo_record_start);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,cpuinfo_record_start,cm_cpuinfo_record_start);
    }
    else if(0 == strcmp("RECORD_READ",cmd[2]))
    {
        cm_thread_runtime_t info[200] = {0};
        uint32_t cnt = atoi(cmd[3]);
        uint32_t total_tick = 0;
        int32_t cpuinfo_record_read = cm_cpuinfo_record_read(info, &cnt, &total_tick);
        cm_demo_printf("cm_cpuinfo_record_read ret:%d\n",cpuinfo_record_read);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,cpuinfo_record_read,cm_cpuinfo_record_read);
        if(0 == cnt)
        {
            cm_demo_printf("read cnt == 0\n");
            return;
        }
        cm_demo_printf("cnt:%u, total_tick:%u\n",cnt,total_tick);
        for(int i = 0;i<cnt;++i)
        {
            cm_demo_printf("info[%d].handle:%p,last_tick:%u,scheduled_cnt:%u,tick_cnt:%u\n",i,(info[i]).handle,(info[i]).last_tick,(info[i]).scheduled_cnt,(info[i]).tick_cnt);
        }
    }
    else if(0 == strcmp("RECORD_STOP",cmd[2]))
    {
        int32_t cpuinfo_record_stop = cm_cpuinfo_record_stop();
        cm_demo_printf("cm_cpuinfo_record_stop ret:%d\n",cpuinfo_record_stop);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,cpuinfo_record_stop,cm_cpuinfo_record_stop);
    }
    else if(0 == strcmp("GET_CPUID",cmd[2]))
    {
        const char *cpuinfo_get_cpuid = cm_cpuinfo_get_cpuid();
        cm_demo_printf("cm_cpuinfo_get_cpuid ret:%s\n",cpuinfo_get_cpuid);
        OCTEST_FUNC_EXPECT_NOT_NULL(cpuinfo_get_cpuid,cm_cpuinfo_get_cpuid);
    }
    else{
        cm_demo_printf("param error!\n");
    }
}